package com.faiz.algorithm;

public class Barrel {
    public static int solution(int[] array) {
        int result = 0;
        if (array == null || array.length == 0) {
            return -1;
        }
        int i = 0;
        int j = array.length - 1;
        result = volume(array, i, j);
        while (i < j) {
            int temp;
            if (array[i] < array[j]) {
                i++;
            } else {
                j--;
            }
            temp = volume(array, i, j);
            if (temp > result) {
                result = temp;
            }
        }
        return result;
    }

    public static int volume(int[] array, int i, int j) {
        return Math.min(array[i], array[j]) * (j - i);
    }
}
